﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace PSSsoft.Web
{
    /// <summary>
    /// ajaxHandlerValidateCode 的摘要说明
    /// </summary>
    public class ajaxHandlerValidateCode : IHttpHandler, System.Web.SessionState.IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            String validateCode = context.Request["validateCode"];
            String userName = context.Request["userName"];
            String userPwd = context.Request["userPwd"];
            if (String.Compare(context.Session["checkCode"].ToString(), validateCode) == 0)
            {
                if (userName.Equals("张三") && userPwd.Equals("zhangsan"))
                {
                    //验证码、用户名、密码均正确
                    context.Response.Write("1");
                    return;
                }
                else if (!userName.Equals("张三") && userPwd.Equals("zhangsan"))
                {
                    //验证码正确，但是用户名不存在
                    context.Response.Write("2");
                    return;
                }
                else if (userName.Equals("张三") && !userPwd.Equals("zhangsan"))
                {
                    //验证码正确，密码错误
                    context.Response.Write("3");
                    return;
                }
                else
                {
                    //系统错误
                    context.Response.Write("4");
                    return;
                }
            }
            else
            {
                //验证码错误
                context.Response.Write("0");
                return;
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}